{extend name="public:base" /}
{block name="title"}后台管理-修改管理员{/block}
{block name="body"}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="account" class="layui-form-label">
                  <span class="x-red">*</span>账号
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="ids" value="{$userInfo['id']}" hidden="hidden"> 
                  <input type="text" id="account" name="account" value="{$userInfo['account']}" disabled="disabled" required="" lay-verify="account"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>账号不允许修改
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>手机
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="phone" name="phone" value="{$userInfo['phone']}" required="" lay-verify="phone"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名
              </div>
          </div>
          <div class="layui-form-item">
              <label for="email" class="layui-form-label">
                  <span class="x-red">*</span>邮箱
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="email" name="email" value="{$userInfo['email']}" required="" lay-verify="email"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="name" class="layui-form-label">
                  <span class="x-red">*</span>用户名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" value="{$userInfo['name']}" required="" lay-verify="name"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="group" class="layui-form-label"><span class="x-red">*</span>角色</label>
              <div class="layui-input-block">
                {volist name="userGroup" id="v"}
                <input type="radio" name="group" value="{$v['id']}" {eq name="$userInfo['admin_user_group_id']" value="$v['id']"} checked="checked" {/eq} lay-skin="primary" title="{$v['name']}">
                {/volist}
              </div>
          </div>
          <div class="layui-form-item">
              <label for="password" class="layui-form-label">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password" name="password" lay-verify="password"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  6到16个字符（不输入则不修改）
              </div>
          </div>
          <div class="layui-form-item">
              <label for="repassword" class="layui-form-label">
                  <span class="x-red">*</span>确认密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="repassword" name="repassword" lay-verify="repassword"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  type="button" class="layui-btn" lay-filter="add" lay-submit="">
                  修改
              </button>
          </div>
      </form>
    </div>
</div>
        
{/block}

{block name="js"}
    <script>
      layui.use(['form', 'layer'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
            layer = layui.layer;

            //自定义验证规则
            form.verify({
                account: function(value) {
                    if (value.length < 2) {
                        return '昵称至少得2个字符！';
                    }
                    if (value.length >= 25) {
                        return '昵称至多得25个字符！';
                    }
                },
                phone: [/^1[3456789]\d{9}$/, '手机号码格式'],
                email: [/^[_a-z0-9-]*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/, '邮箱格式错误'],
                repassword: function(value) {
                    let pwd = $('#password').val();
                    let repwd = $('#repassword').val();
                    let reg = /^(.+){6,12}$/;
                    if(pwd){
                      if(!reg.test(pwd)){
                        return '密码必须6到12位';
                      }
                    }
                    if(pwd||repwd){
                      if (pwd != repwd) {
                          return '两次密码不一致';
                      }
                    }
                    
                    //验证是否有选择用户组
                    if(!$('input[name="group"]:checked').val()){
                       return '请选择角色';
                    }
                }
            });

            //监听提交
            form.on('submit(add)',
            function(data) {
                console.log(data);
                $.post("{:url('admin/AdminUser/edit')}",data.field,function(e){
                  if(e.code == 200){
                    //发异步，把数据提交给php
                      layer.alert(e.msg, {icon: 6},function () {
                          //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新 
                            xadmin.father_reload();
                      });
                      return false;
                  }
                  layer.alert(e.msg, {
                      icon: 5
                  });
                  return false;
              });
            });

        });</script>
    <script>var _hmt = _hmt || []; (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();</script>
{/block}